clear

use 
***file path for V-Dem-CY-Full+Others-v14.dta ***

*** Preparing Data

*** Cleaning name variables

gen histnamecopy = histname

gen s = ustrregexra(histnamecopy,"\[.+?\]","")

split s, parse(,) gen(stub_)

drop histnamecopy stub_2  stub_3  stub_4  stub_5  stub_6  stub_7

rename s onlyhistname

rename stub_1 onlyhistnamecopy

***Creating the descriptor variables

*** Monarchies

gen emirate = 0
replace emirate = 1 if strpos(onlyhistname,"Emirate") >= 1

gen kingdom = 0
replace kingdom = 1 if strpos(onlyhistname,"Kingdom") >= 1

gen empire = 0
replace empire = 1 if strpos(onlyhistname,"Empire") >= 1

gen hereditary = 0
replace hereditary = 1 if strpos(onlyhistname,"hereditary") >= 1

gen beylik = 0
replace beylik = 1 if strpos(onlyhistname,"Beylik") >= 1

gen khaan = 0
replace khaan = 1 if strpos(onlyhistname,"Khaan") >= 1

gen daivietquoc = 0
replace daivietquoc = 1 if strpos(onlyhistname,"Dai Viet Quoc") >= 1

gen duchy = 0
replace duchy = 1 if strpos(onlyhistname,"Duchy") >= 1

gen duchies = 0
replace duchies = 1 if strpos(onlyhistname,"Duchies") >= 1

gen electorate = 0
replace electorate = 1 if strpos(onlyhistname,"Electorate") >= 1

gen landgraviate = 0
replace landgraviate = 1 if strpos(onlyhistname,"Landgraviate") >= 1

gen principality = 0
replace principality = 1 if strpos(onlyhistname,"Principality") >= 1

gen principalities = 0
replace principalities = 1 if strpos(onlyhistname,"Principalities") >= 1

gen Monarchical = 0
replace Monarchical = 1 if emirate == 1 | kingdom == 1 | empire == 1 | hereditary == 1 | beylik == 1 | beylik == 1 | khaan == 1 | daivietquoc == 1 | duchy == 1 | duchies == 1 | electorate == 1 | landgraviate == 1 | principality == 1 | principalities == 1


*** Republic

gen republic = 0
replace republic = 1 if strpos(onlyhistname,"Republic") >= 1

gen commonwealth = 0
replace commonwealth = 1 if strpos(onlyhistname,"Commonwealth") >= 1

gen Republican = 0
replace Republican = 1 if republic == 1 | commonwealth == 1

*** Religion

gen islamic = 0
replace islamic  = 1 if strpos(onlyhistname,"Islamic") >= 1

gen papal = 0
replace papal = 1 if strpos(onlyhistname,"Papal") >= 1

gen bishopric = 0
replace bishopric = 1 if strpos(onlyhistname,"Bishopric") >= 1

gen Religious = 0
replace Religious = 1 if islamic == 1 | papal == 1 | bishopric == 1 

*** Democratic

gen Democratic = 0
replace Democratic = 1 if strpos(onlyhistname,"Democratic") >= 1

*** Socialist 

gen socialist = 0
replace socialist = 1 if strpos(onlyhistname,"Socialist") >= 1

gen soviet = 0
replace soviet = 1 if strpos(onlyhistname,"Soviet") >= 1

gen sovietsocialist = 0
replace sovietsocialist = 1 if soviet == 1 | socialist == 1

gen people = 0
replace people = 1 if strpos(onlyhistname,"People") >= 1

gen jamahiriya = 0
replace jamahiriya = 1 if strpos(onlyhistname,"Jamahiriya") >= 1

gen allpeople = 0
replace allpeople = 1 if jamahiriya == 1 | people == 1

gen Socialist = 0

replace Socialist = 1 if sovietsocialist == 1 | allpeople == 1

 
 *** Creating Controls
 
 gen population = .
 
 replace population = e_mipopula if  e_mipopula != .
 
 replace population = (e_wb_pop/1000) if e_wb_pop != .

 gen lnpopulation = ln(population)
 
 gen lnGDPpercap = ln(e_gdppc)
 
 
 **** Running Models 
 
 ***Monarchy
 
 gen Monarchicalsuccession = 0 
 replace Monarchicalsuccession = 1 if v2expathhs == 3 
 replace Monarchicalsuccession = 1 if v2expathhs == 4
 replace Monarchicalsuccession = . if v2expathhs == .

 
gen HoSlifetimetenure = 0 
replace HoSlifetimetenure = 1 if v2exfxtmhs == 100
replace HoSlifetimetenure = . if v2exfxtmhs == .
 
 
 logit  Monarchicalsuccession Monarchical lnpopulation lnGDPpercap if year == 2019
 estimates store A
outreg2 using namestableOLS1.doc, replace ctitle(Monarchical Succession) label
 
 logit  Monarchicalsuccession Monarchical lnpopulation lnGDPpercap if year > 1945, 
 
  ttest  Monarchicalsuccession if year == 1855, by(Monarchical) 
 
 logit  HoSlifetimetenure Monarchical lnpopulation lnGDPpercap if year == 2019
  estimates store B
outreg2 using namestableOLS1.doc, append ctitle(Head of State Lifetime Tenure) label

  
 logit  HoSlifetimetenure Monarchical lnpopulation lnGDPpercap if year > 1945, 
 
  logit  Monarchicalsuccession Monarchical lnpopulation lnGDPpercap if year > 1945, 

   ttest  HoSlifetimetenure if year == 1900, by(Monarchical) 

   
*** Republican

gen Republicansuccession = 0 
 replace Republicansuccession = 1 if v2expathhs == 6 
 replace Republicansuccession = 1 if v2expathhs == 7
   replace Republicansuccession = . if v2expathhs == .


gen HoStermlimits = 0 
replace HoStermlimits = 1 if v2exfxtmhs < 99
replace HoStermlimits = 0 if v2exfxtmhs == 0
replace HoStermlimits = . if v2exfxtmhs == .

logit  Republicansuccession Republican lnpopulation lnGDPpercap if year == 2019
 estimates store C
 outreg2 using namestableOLS1.doc, append ctitle(Republican Succession) label
 
 logit  Republicansuccession Republican lnpopulation lnGDPpercap if year > 1945, 
    ttest  Republicansuccession if year == 2016, by(Republican) 


 logit  HoStermlimits Republican lnpopulation lnGDPpercap if year == 2019
  estimates store D
   outreg2 using namestableOLS1.doc, append ctitle(Head of State Term Limits) label

  
 logit  HoStermlimits Republican lnpopulation lnGDPpercap if year > 1945, 
     ttest  HoStermlimits if year == 2016, by(Republican) 
	 
	 
 regress  v2x_polyarchy Republican lnpopulation lnGDPpercap if year == 2019
   estimates store J
      outreg2 using namestableOLS1.doc, append ctitle(Republican Democracy) label

 
  regress  v2x_polyarchy Republican lnpopulation lnGDPpercap if year > 1945
	     ttest  v2x_polyarchy if year == 2016, by(Republican) 

	

***Religious
 
 gen Religiousfreedom = v2clrelig / 4
 
 regress  Religiousfreedom Religious lnpopulation lnGDPpercap if year == 2019
  estimates store F
        outreg2 using namestableOLS2.doc, replace ctitle(Religious Freedom) label

  
          ttest  Religiousfreedom if year == 1996, by(Religious) 
        ttest  Religiousfreedom if year == 2011, by(Religious) 


 regress v2exl_legitideolcr_4 Religious lnpopulation lnGDPpercap if year == 2019
   estimates store G
           outreg2 using namestableOLS2.doc, append ctitle(Religious Legitimation) label


       ttest  v2exl_legitideolcr_4 if year == 1996, by(Religious) 
        ttest  v2exl_legitideolcr_4 if year == 2011, by(Religious) 
 
   ***Socialist
	  
	  gen Stateownership = -(v2clstown_osp / 4)
	  
	  regress v2xeg_eqdr Socialist  lnpopulation lnGDPpercap if year == 2019
   estimates store H
              outreg2 using namestableOLS2.doc, append ctitle(Socialist Equal Resources) label

   
        ttest  v2xeg_eqdr if year == 1983, by(Socialist) 
        ttest  v2xeg_eqdr if year == 1990, by(Socialist) 

   
	  regress Stateownership Socialist  lnpopulation lnGDPpercap if year == 2019
   estimates store I
                 outreg2 using namestableOLS2.doc, append ctitle(Socialist State Ownership) label

        ttest  Stateownership if year == 1983, by(Socialist) 
        ttest  Stateownership if year == 1990, by(Socialist) 

	  
	  
	  ttest v2xeg_eqdr if year == 1990, by(Socialist)
	  ttest v2xeg_eqdr if year == 1983, by(Socialist)
  ttest Stateownership if year == 1990, by(Socialist)
	  ttest Stateownership if year == 1983, by(Socialist)

	  
 
 ***Democratic
 
 regress  v2x_polyarchy Democratic lnpopulation lnGDPpercap if year == 2019
  estimates store E
               outreg2 using namestableOLS2.doc, append ctitle(Democratic Democracy) label

  
     ttest  v2x_polyarchy if year == 1990, by(Democratic) 
     ttest  v2x_polyarchy if year == 1978, by(Democratic) 
	 
  regress v2xeg_eqdr Democratic  lnpopulation lnGDPpercap if year == 2019
   estimates store K
     outreg2 using namestableOLS2.doc, append ctitle(Democratic Equal Resources) label

   
regress Stateownership Democratic  lnpopulation lnGDPpercap if year == 2019
   estimates store L
     outreg2 using namestableOLS2.doc, append ctitle(Democratic State Ownership) label

	 	 
*** Figures 2 and 3

coefplot ///
(A, label(Monarchical Succession dropped) msymbol(d) msize(medlarge) pstyle(p1) offset(0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(B, label(Head of State Life Tenure) msymbol(Dh) msize(medlarge) pstyle(p2) offset(-0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(C, label(Republican Succession) msymbol(o) msize(medlarge) pstyle(p3) offset(0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(D, label(Head of State Limited Term) msymbol(Oh) msize(medlarge) pstyle(p4) offset(-0.15) drop(_cons lnpopulation lnGDPpercap)), ///
plotregion(fcolor(white)) graphregion(fcolor(white)) bgcolor(fcolor(white)) ///
xline(0) xscale(range(0 10)) ///
xtitle("Coefficients with 95% Confidence Intervals", size(medium) margin(medsmall))


coefplot  ///
(J, label(Polyarchy) msymbol(O) pstyle(p5) msize(medlarge) offset(0) drop(_cons lnpopulation lnGDPpercap))  ///
(F, label(Religious Freedom) msymbol(T) pstyle(p6) msize(medlarge) offset(0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(G, label(Religious Legitimation) msymbol(Th) pstyle(p7) msize(medlarge) offset(-0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(H, label(Equal Resources) msymbol(S) pstyle(p8) msize(medlarge) offset(0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(I, label(State Ownership) msymbol(Sh) pstyle(p9) msize(medlarge) offset(-0.15) drop(_cons lnpopulation lnGDPpercap)) ///
(E, label("") msymbol(O) nokey pstyle(p5) msize(medlarge) offset(0.25) drop(_cons lnpopulation lnGDPpercap)) ///
(K, label("") msymbol(S) nokey pstyle(p8) msize(medlarge) offset(0.0) drop(_cons lnpopulation lnGDPpercap)) ///
(L, label("") msymbol(Sh) nokey pstyle(p9) msize(medlarge) offset(-0.25) drop(_cons lnpopulation lnGDPpercap)), ///
plotregion(fcolor(white)) drop(_cons lnpopulation lnGDPpercap) ///
xline(0) xtitle("Coefficients with 95% Confidence Intervals", size(medium) margin(medsmall))
